package com.bk;
import java.util.Comparator;

import com.mj.printer.BinaryTrees;

//import com.bk.BinarySearchTree;
import com.bk.BinarySearchTree.Visitor;

public class Main {

	public static void main(String[] args) {
//		test();

		test7();

//
//		BinarySearchTree<Car> bstc = new BinarySearchTree<Car>(new Comparator<Car>() {
//			public int compare(Car c1, Car c2) {
//				return c1.used - c2.used;
//			}
//		});

//		BinarySearchTree<Integer> bst = new BinarySearchTree<Integer>();
//		bst.add(7);
//		bst.add(4);
//		bst.add(9);
//		bst.add(2);
//		bst.add(5);
//		bst.add(8);
//		bst.add(11);
//		bst.add(3);
//		BinaryTrees.print(bst);
	}

	static void test5() {
		int[] array = new int[] { 15, 2, 3, 1, 8, 11, 9, 6 };

		BinarySearchTree<Integer> bst = new BinarySearchTree<Integer>();
		for (int i = 0; i < array.length; i++) {
			bst.add(array[i]);
		}

		BinaryTrees.println(bst);
		bst.invertTree();

		BinaryTrees.println(bst);
		;
	}

	static void test() {
		int[] array = new int[] { 7, 10, 5, 4, 6, 1, 12, 9, 20 };

		BinarySearchTree<Person> bst = new BinarySearchTree<Person>(new Comparator<Person>() {
			public int compare(Person p1, Person p2) {
				return p1.age - p2.age;
			}
		});
		for (int i = 0; i < array.length; i++) {
			bst.add(new Person(array[i]));
		}
		BinaryTrees.print(bst);
		System.out.println("\n");
//		bst.preorderTraversalPrint();
//		bst.inorderTraversalPrint();
//		bst.postorderTraversalPrint();

	}

	static void test1() {
		int[] array = new int[] { 7, 10, 5, 4, 6, 1, 12, 9, 20 };

		BinarySearchTree<Integer> bst = new BinarySearchTree<Integer>();
		for (int i = 0; i < array.length; i++) {
			bst.add(array[i]);
		}
		BinaryTrees.println(bst);

		bst.inorder(new Visitor<Integer>() {

			@Override
			public boolean visit(Integer element) {
				System.out.print("=======" + element);
				return element == 4 ? true : false;

			}
		});

	}

	static void test2() {
		int[] array = new int[] { 7, 10, 5, 4, 6, 1, 12, 9, 20 };

		BinarySearchTree<Integer> bst = new BinarySearchTree<Integer>();
		for (int i = 0; i < array.length; i++) {
			bst.add(array[i]);
		}
		BinaryTrees.println(bst);
//		bst.levelorderTraversalPrint();

		bst.levelorder(new Visitor<Integer>() {
			public boolean visit(Integer element) {
				System.out.print("=======" + element);
				return element == 4 ? true : false;
			}
		});

	}

	static void test3() {
		int[] array = new int[] { 7, 10, 5, 4, 6, 1, 12, 9, 20 };

		BinarySearchTree<Integer> bst = new BinarySearchTree<Integer>();
		for (int i = 0; i < array.length; i++) {
			bst.add(array[i]);
		}
		BinaryTrees.println(bst);

		bst.postorder(new Visitor<Integer>() {
			public boolean visit(Integer element) {
				System.out.print("=======" + element);
				return element == 5 ? true : false;
			}
		});

	}

	static void test4() {
		int[] array = new int[] { 7, 10, 5, 4, 6, 1, 12, 9, 20 };

		BinarySearchTree<Integer> bst = new BinarySearchTree<Integer>();
		for (int i = 0; i < array.length; i++) {
			bst.add(array[i]);
		}
		BinaryTrees.println(bst);
		System.out.println(bst.height2());
		System.out.println(bst.isComplete(null));

	}

	static void test6() {
		int[] array = new int[] { 1, 3, 2, 5 };

		BinarySearchTree<Integer> bst = new BinarySearchTree<Integer>();
		for (int i = 0; i < array.length; i++) {
			bst.add(array[i]);
		}
		BinaryTrees.println(bst);

		bst.postorder(null);

//		bst.preorderTraversalIterate( new Visitor<Integer>() {
//			public boolean visit(Integer element) {
//				System.out.print("=======" + element);
//				return true;
//			}
//		});

	}

	static void test7() {
//		System.out.print("test7");
		int[] array = new int[] { 1,3,2,5,3,9 };

		BinarySearchTree<Integer> bst = new BinarySearchTree<Integer>();
		for (int i = 0; i < array.length; i++) {
			bst.add(array[i]);
		}
		BinaryTrees.println(bst);

		int width = bst.widthOfBinaryTree();
		System.out.print(width);
	}
}
